<template>
  <div class="content-one" slot="content">
    <div class="content-box" v-for="item, index in ContentList" :key="index">
      <div class="content-tab">
        <img :src="item.user.userpic !== null ? item.user.userpic : userImgUrl" @error="imgError">
        <div class="content">
          <p class="p1">{{ item.user.username }}</p>
          <p class="p2" >{{ item.create_time }}</p>
        </div>
      </div>
      <p class="content-p">{{ item.content }}</p>
      <!-- 相同高度的图片 -->
      <div class="content-box1" v-show="item.titlepic">
        <img :src="item.titlepic" class="content-img">
      </div>
      <!-- 完全展示出来的图片 -->
      <!-- <img :src="item.titlepic" alt="" class="content-img" v-show="item.titlepic"> -->
      <div class="content-bottom">
        <div class="bottom">
          <i class="iconfont">&#xe613;</i>
          <div class="bottom-content" v-if="!item.ding_count">支持</div>
          <div class="bottom-content" v-else>{{ item.ding_count }}</div>
        </div>
        <div class="bottom">
          <i class="iconfont">&#xe614;</i>
          <div class="bottom-content" v-if="!item.cai_count">反对</div>
          <div class="bottom-content" v-else>{{ item.cai_count }}</div>
        </div>
        <div class="bottom">
          <i class="iconfont">&#xe616;</i>
          <div class="bottom-content" v-if="!item.comment_count">评论</div>
          <div class="bottom-content" v-else>{{ item.comment_count }}</div>
        </div>
        <div class="bottom">
          <i class="iconfont">&#xe653;</i>
          <div class="bottom-content">分享</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 需要用require包裹
      userImgUrl: require('../../assets/image/default.jpg')
    }
  },
  props: {
    ContentList: {
      type: Array,
      required: true
    }
  },
  methods: {
    // 当用户头像上传了但上传失败了
    imgError(e) {
      // 当前用户的头像路径
      // console.log(e.target.src);
      // 上传失败就把默认头像放上
      e.target.src = this.userImgUrl
    }
  }
}
</script>

<style lang="scss" scoped>
$width: 100%;

.content-one {
  background-color: #f5f5f4;

  .content-box {
    width: 94%;
    padding-left: 3%;
    margin-bottom: 10px;
    background-color: #fff;

    .content-box1 {
      position: relative;
      height: 175px;
      width: $width;
      overflow: hidden;

      img {
        position: absolute;
        bottom: -30px;
      }
    }

    .content-tab {
      height: 48px;
      margin: auto;
      display: flex;
      align-items: center;
      margin-top: 5px;
      margin-bottom: 5px;

      img {
        width: 32px;
        height: 32px;
        border-radius: 50%;
      }

      .content {
        display: flex;
        flex-direction: column;
        margin-left: 15px;

        .p1 {
          font-size: 15px;
          margin-top: 10px;
        }

        .p2 {
          font-size: 12px;
          margin-top: 10px;
          color: #A9A5A0;
        }
      }
    }

    .content-p {
      font-size: 17px;
      margin-top: 5px;
      line-height: 30px;
    }

    .content-img {
      width: $width;
      height: 175px;
      margin-top: 10px;
      max-width: 100%;
      height: auto;
    }

    .content-bottom {
      width: 355px;
      height: 30px;
      display: flex;
      background-color: #fff;
      margin-top: 15px;
      padding-bottom: 15px;
      line-height: 30px;

      .bottom {
        width: 25%;
        display: flex;
        justify-content: center;

        i {
          font-size: 20px;
        }

        .bottom-content {
          font-size: 14px;
          margin-left: 5px;
        }
      }
    }
  }
}
</style>